/**
 * Copyright 2019 Inc.
 **/
package com.myz.service.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Objects;

/**
 * 根据Hostname进行限流，则需要用hostAddress去判断
 *
 * @author maoyz0621 on 19-3-14
 * @version: v1.0
 */
public class HostAddrKeyResolver implements KeyResolver {

    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        return Mono.just(Objects.requireNonNull(exchange.getRequest().getRemoteAddress())
                .getAddress()
                .getHostAddress());
    }
}
